package com.vis.mybatisflex.config;

import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.ConsoleMessageCollector;
import com.mybatisflex.core.audit.MessageCollector;
import com.mybatisflex.core.query.QueryColumnBehavior;
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan({"com.vis.mybatisflex.mapper"})
public class MyBatisFlexConfig implements MyBatisFlexCustomizer {

    private static final Logger logger = LoggerFactory.getLogger("SQL");

    @Override
    public void customize(FlexGlobalConfig globalConfig) {
        // 使用内置规则自动忽略 null 和 空字符串
        QueryColumnBehavior.setIgnoreFunction(QueryColumnBehavior.IGNORE_EMPTY);

        // 使用内置规则自动忽略 null 和 空白字符串
        QueryColumnBehavior.setIgnoreFunction(QueryColumnBehavior.IGNORE_BLANK);

        //如果传入的值是集合或数组，则使用 in 逻辑，否则使用 =（等于） 逻辑：
        QueryColumnBehavior.setSmartConvertInToEquals(true);

        //全局逻辑删除字段 del
        globalConfig.setLogicDeleteColumn("del");

        //开启审计功能
        AuditManager.setAuditEnable(true);

        //设置 SQL 审计收集器
        MessageCollector collector = new ConsoleMessageCollector();
        AuditManager.setMessageCollector(collector);

        //脱敏规则
        //        MaskManager.registerMaskProcessor("removePassword", data -> null);

    }

}